package com.ehotting.edsta.circuitDesign.mqbd;

import com.alibaba.fastjson.JSONObject;
import com.ehotting.mqbd.api.MqActionConstants;
import com.ehotting.mqbd.api.bean.CommonRequest;
import com.ehotting.mqbd.api.bean.CommonResponse;
import com.ehotting.mqbd.api.bean.MQHttpData;
import com.ehotting.mqbd.api.bean.MqApplicationContext;
import com.ehotting.mqbd.api.enums.MQDataPushModelEnum;
import com.ehotting.mqbd.api.enums.TopicEnum;

import java.util.HashMap;
import java.util.Map;

public class MqdbRequestDataHelper {

    public static MQHttpData rePost(MqApplicationContext mqApplicationContext, String agentId, String authorization, JSONObject rePostBody,String serial){

        Map<String, Object> webInfo = new HashMap<>();
        webInfo.put("serial",serial);

        CommonRequest commonRequest = new CommonRequest();
        commonRequest.setRequestBody(rePostBody);
        commonRequest.setRequestMethod("post");
        commonRequest.setRequestUrl(MqdbUrlConstants.Start_Solving);
        commonRequest.setWebInfo(webInfo);

        MQHttpData data = MQHttpData.create(
                TopicEnum.CONCURRENCY,
                mqApplicationContext,
                agentId,
                "");
        data.setAction(MqActionConstants.RE_POST);
        data.setRequest(commonRequest);
        data.setAuthorization(authorization);
        data.setSerial(serial);
        data.setPushModel(MQDataPushModelEnum.WEBSOCKET_PUSH);
        return data;
    }


    public static MQHttpData taskCancel(MqApplicationContext mqApplicationContext, String agentId, String authorization, JSONObject rePostBody,String serial){

        Map<String, Object> webInfo = new HashMap<>();
        webInfo.put("serial",serial);

        CommonRequest commonRequest = new CommonRequest();
        commonRequest.setRequestBody(rePostBody);
        commonRequest.setRequestMethod("post");
        commonRequest.setRequestUrl(MqdbUrlConstants.Stop_Solving);
        commonRequest.setWebInfo(webInfo);

        MQHttpData data = MQHttpData.create(
                TopicEnum.CONCURRENCY,
                mqApplicationContext,
                agentId,
                "");
        data.setAction(MqActionConstants.RE_POST);
        data.setRequest(commonRequest);
        data.setAuthorization(authorization);
        data.setPushModel(MQDataPushModelEnum.HTTP_PUSH);
        return data;
    }


    public static MQHttpData returnTaskCancel(MqApplicationContext mqApplicationContext, String agentId,String mainProjectId,String serial){

        Map<String, Object> map = new HashMap<>();
        map.put("code",500);
        map.put("msg","匹配已停止:"+mainProjectId);

        Map<String, Object> webInfo = new HashMap<>();
        webInfo.put("serial",serial);

        CommonResponse commonRequest = new CommonResponse();
        commonRequest.setResponse(map);
        commonRequest.setWebInfo(webInfo);

        MQHttpData data = MQHttpData.create(
                TopicEnum.CONCURRENCY,
                mqApplicationContext,
                agentId,
                "");
        data.setResponse(commonRequest);
        return data;
    }
}
